//
//  YYInviteVC.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/10/4.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "YYInviteVC.h"
#import <UMSocialCore/UMSocialCore.h>
#import <UShareUI/UShareUI.h>

@interface YYInviteVC ()<UMSocialShareMenuViewDelegate>

@end

@implementation YYInviteVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
    // Do any additional setup after loading the view.
}

- (void)getData{
    [RequestOperationManager personalInvite_success:^(id result) {
        
        if (DEF_REQ_SUCCESS) {
            self.lbNUmber.text = result[@"data"][@"code"];
        }
        
    } failture:^(NSError *error) {
        
    }];
}
- (IBAction)invite:(id)sender {
//    if (self.lbNUmber.text.length == 0) {
//        [AlertUtil alertMessage:@"获取邀请码失败，请稍后再试"];
//        return;
//    }
    [self share];
}

- (void)share{
   [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_Qzone)]];
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根据获取的platformType确定所选平台进行下一步操作
        [self shareWebPageToPlatformType:platformType];

    }];
    [UMSocialUIManager setShareMenuViewDelegate:self];

    //设置ShareMenuView的代理，实现点击取消分享的时候移除imageView
   
}
- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    
    //创建网页内容对象
    NSString* thumbURL =  @"https://jskj0527.com/logo.png";
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"来自嘀车惠的邀请函" descr:@"您的好友在嘀车惠拿到驾照并提新车啦！快来围观吧！" thumImage:thumbURL];
    //设置网页地址
    shareObject.webpageUrl = [NSString stringWithFormat:@"%@/api/share/index?code=%@&uid=%@",DEF_INTERFACE_WEBVIEWSERVICE,self.lbNUmber.text,DEF_UID];
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
    }];
}

//- (void)shareImageToPlatformType:(UMSocialPlatformType)platformType
//{
//
//
//
//    //创建分享消息对象
//    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//    UMShareWebpageObject *shareObject = [[UMShareWebpageObject alloc] init];
//    NSString * url = [NSString stringWithFormat:@"%@/api/share/index?code=%@&uid=%@",DEF_INTERFACE_WEBVIEWSERVICE,self.lbNUmber.text,DEF_UID];
//    shareObject.webpageUrl =url;
//
//    //分享消息对象设置分享内容对象
//    messageObject.shareObject = shareObject;
//
//    //调用分享接口
//    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
//
//        if (error) {
//            NSLog(@"************Share fail with error %@*********",error);
//        }else{
//            NSLog(@"response data is %@",data);
//        }
//
//    }];
//}

@end
